package com.smart.model.convert;

import com.smart.model.dtomapper.ProjectItemDtoMapper;
import com.smart.model.domain.ProjectItemDO;
import com.smart.model.request.ProjectItemAddRequest;
import com.smart.model.request.ProjectItemUpdateRequest;
import com.smart.model.vo.ProjectItemVO;
import com.google.common.collect.Lists;
import org.apache.commons.collections4.CollectionUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author zhanghong
 */
public class ProjectItemConvert {

    public static List<ProjectItemVO> buildProjectItemVoList(List<ProjectItemDO> projectItemDOList) {
        if (CollectionUtils.isEmpty(projectItemDOList)) {
            return Lists.newArrayList();
        }
        List<ProjectItemVO> projectItemVOList = new ArrayList<>();
        for (ProjectItemDO projectItemDO : projectItemDOList) {
            projectItemVOList.add(ProjectItemDtoMapper.INSTANCE.do2VO(projectItemDO));
        }

        return projectItemVOList;
    }

    public static List<ProjectItemDO> buildProjectAddItemDOList(List<ProjectItemAddRequest> items) {
        if (CollectionUtils.isEmpty(items)) {
            return Lists.newArrayList();
        }

        return items.stream().map(ProjectItemDtoMapper.INSTANCE::request2DO).collect(Collectors.toList());
    }

    public static List<ProjectItemDO> buildProjectUpdateItemDOList(List<ProjectItemUpdateRequest> items) {
        if (CollectionUtils.isEmpty(items)) {
            return Lists.newArrayList();
        }

        return items.stream().map(ProjectItemDtoMapper.INSTANCE::request2DO).collect(Collectors.toList());
    }
}
